{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  谢新沪\n",
    "+ 学号  0162485"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "又回到最初的起点 记忆中你青涩的脸\n",
      "我们终于 来到了这一天 桌垫下的老照片\n",
      "无数回忆连结 今天男孩要赴女孩最后的约\n",
      "\n",
      "又回到最初的起点 呆呆地站在镜子前 笨拙系上红色领带的结\n",
      "将头发梳成大人模样 穿上一身帅气西装 等会儿见你一定比想象美\n",
      "好想再回到那些年的时光 回到教室座位前后 故意讨你温柔的骂\n",
      "黑板上排列组合 你舍得解开吗 谁与谁坐他又爱着她\n",
      "\n",
      "那些年错过的大雨 那些年错过的爱情 好想拥抱你\n",
      "拥抱错过的勇气 曾经想征服全世界 到最后回首才发现\n",
      "这世界滴滴点点全部都是你 那些年错过的大雨 那些年错过的爱情\n",
      "好想告诉你 告诉你我没有忘记 那天晚上满天星星\n",
      "平行时空下的约定 再一次相遇我会 紧紧抱着你 紧紧抱着你\n",
      "\n",
      "又回到最初的起点 呆呆地站在镜子前 笨拙系上红色领带的结\n",
      "将头发梳成大人模样 穿上一身帅气西装 等会儿见你一定比想象美\n",
      "好想再回到那些年的时光 回到教室座位前后 故意讨你温柔的骂\n",
      "黑板上排列组合 你舍得解开吗 谁与谁坐他又爱着她\n",
      "\n",
      "那些年错过的大雨 那些年错过的爱情 好想拥抱你\n",
      "拥抱错过的勇气 曾经想征服全世界 到最后回首才发现\n",
      "这世界滴滴点点全部都是你 那些年错过的大雨 那些年错过的爱情\n",
      "好想告诉你 告诉你我没有忘记 那天晚上满天星星\n",
      "平行时空下的约定 再一次相遇我会 紧紧抱着你 紧紧抱着你\n",
      "\n",
      "那些年错过的大雨 那些年错过的爱情 好想拥抱你\n",
      "拥抱错过的勇气 曾经想征服全世界 到最后回首才发现\n",
      "这世界滴滴点点全部都是你 那些年错过的大雨 那些年错过的爱情\n",
      "好想告诉你 告诉你我没有忘记 那天晚上满天星星\n",
      "平行时空下的约定 再一次相遇我会 紧紧抱着你 紧紧抱着你\n"
     ]
    }
   ],
   "source": [
    "def repeat1():\n",
    "    print(\"\\n又回到最初的起点 呆呆地站在镜子前 笨拙系上红色领带的结\")\n",
    "    print(\"将头发梳成大人模样 穿上一身帅气西装 等会儿见你一定比想象美\")\n",
    "    print(\"好想再回到那些年的时光 回到教室座位前后 故意讨你温柔的骂\")\n",
    "    print(\"黑板上排列组合 你舍得解开吗 谁与谁坐他又爱着她\")\n",
    "def repeat2():\n",
    "    print(\"\\n那些年错过的大雨 那些年错过的爱情 好想拥抱你\")\n",
    "    print(\"拥抱错过的勇气 曾经想征服全世界 到最后回首才发现\")\n",
    "    print(\"这世界滴滴点点全部都是你 那些年错过的大雨 那些年错过的爱情\")\n",
    "    print(\"好想告诉你 告诉你我没有忘记 那天晚上满天星星\")\n",
    "    print(\"平行时空下的约定 再一次相遇我会 紧紧抱着你 紧紧抱着你\")\n",
    "print(\"又回到最初的起点 记忆中你青涩的脸\")\n",
    "print(\"我们终于 来到了这一天 桌垫下的老照片\")\n",
    "print(\"无数回忆连结 今天男孩要赴女孩最后的约\")\n",
    "repeat1()\n",
    "repeat2()\n",
    "repeat1()\n",
    "repeat2()\n",
    "repeat2()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请以空格为间隔连续输入10个以上的数字：1 2 3 4 5 6 7 8 9 10 11\n",
      "均值=6.0\n",
      "方差=10.0\n",
      "n=11\n",
      "请以空格为间隔连续输入10个以上的数字：4 6 4 6 4 6 4 6 4 6 4 6\n",
      "均值=5.0\n",
      "方差=1.0\n",
      "n=12\n"
     ]
    }
   ],
   "source": [
    "def count():\n",
    "    while True:\n",
    "        str_in = input(\"请以空格为间隔连续输入10个以上的数字：\")\n",
    "        num = [int(n) for n in str_in.split()]\n",
    "        if len(num)>10:\n",
    "            break\n",
    "        print(\"输入的数字个数小于10!\")\n",
    "    nsum = 0\n",
    "    for i in range(len(num)):\n",
    "        nsum += num[i]\n",
    "    averagenum = nsum / len(num)\n",
    "    sum1=0\n",
    "    sum2=0\n",
    "    for i in range(len(num)):\n",
    "        sum1 = num[i] - averagenum\n",
    "        sum2  += sum1**2\n",
    "    var=sum2 / len(num)\n",
    "    print(\"均值=%s\" % averagenum)\n",
    "    print(\"方差=%s\" % var)\n",
    "    print(\"n=%s\" % len(num))\n",
    "count()\n",
    "count()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请以空格为间隔连续输入10个以上的数字：1 2 3 4 5 6 7 8 9 10 11 \n",
      "均值=6.0\n",
      "标准差=3.1622776601683795\n",
      "n=11\n",
      "请以空格为间隔连续输入10个以上的数字： 1 2 3 4 5 6 7 8 9 10 11\n",
      "均值=6.0\n",
      "方差=10.0\n",
      "n=11\n"
     ]
    }
   ],
   "source": [
    "def count(difference):\n",
    "    while True:\n",
    "        str_in = input(\"请以空格为间隔连续输入10个以上的数字：\")\n",
    "        num = [int(n) for n in str_in.split()]\n",
    "        if len(num)>10:\n",
    "            break\n",
    "        print(\"输入的数字个数小于10!\")\n",
    "    nsum = 0\n",
    "    for i in range(len(num)):\n",
    "        nsum += num[i]\n",
    "    averagenum = nsum / len(num)\n",
    "    sum1=0\n",
    "    sum2=0\n",
    "    for i in range(len(num)):\n",
    "        sum1 = num[i] - averagenum\n",
    "        sum2  += sum1**2\n",
    "    var=sum2 / len(num)\n",
    "    std = var**0.5 \n",
    "    if difference ==\"方差\":\n",
    "        print(\"均值=%s\" % averagenum)\n",
    "        print(\"方差=%s\" % var)\n",
    "        print(\"n=%s\" % len(num))\n",
    "    elif difference ==\"标准差\":\n",
    "        print(\"均值=%s\" % averagenum)\n",
    "        print(\"标准差=%s\" % std)\n",
    "        print(\"n=%s\" % len(num))\n",
    "    else:\n",
    "        print(\"出错\")\n",
    "count(\"标准差\")\n",
    "count(\"方差\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请以空格为间隔连续输入10个以上的数字：1 2 3 4 5 6 7 8 9 10 11\n",
      "均值=6.0\n",
      "方差=10.0\n",
      "n=11\n",
      "标准差=3.1622776601683795\n",
      "最大值=11\n",
      "最大值=1\n",
      "请以空格为间隔连续输入10个以上的数字：1 2 3 4 5 6 7 8 9 10 11\n",
      "均值=6.0\n",
      "方差=10.0\n",
      "n=11\n"
     ]
    }
   ],
   "source": [
    "def count(stdnum,maximum,minimum):\n",
    "    while True:\n",
    "        str_in = input(\"请以空格为间隔连续输入10个以上的数字：\")\n",
    "        num = [int(n) for n in str_in.split()]\n",
    "        if len(num)>10:\n",
    "            break\n",
    "        print(\"输入的数字个数小于10!\")\n",
    "    nsum = 0\n",
    "    for i in range(len(num)):\n",
    "        nsum += num[i]\n",
    "    averagenum = nsum / len(num)\n",
    "    sum1=0\n",
    "    sum2=0\n",
    "    for i in range(len(num)):\n",
    "        sum1 = num[i] - averagenum\n",
    "        sum2  += sum1**2\n",
    "    var=sum2 / len(num)\n",
    "    std = var**0.5\n",
    "    maxnum = max(num)\n",
    "    minnum = min(num)\n",
    "    print(\"均值=%s\" % averagenum)\n",
    "    print(\"方差=%s\" % var)\n",
    "    print(\"n=%s\" % len(num))\n",
    "    if stdnum ==\"是\":\n",
    "        print(\"标准差=%s\" % std)\n",
    "    if maximum ==\"是\":\n",
    "        print(\"最大值=%s\" % maxnum)\n",
    "    if maximum ==\"是\":\n",
    "        print(\"最大值=%s\" % minnum)\n",
    "count(\"是\",\"是\",\"是\")\n",
    "count(\"否\",\"否\",\"否\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
